/*
 * Printer.java
 *
 * Creada el 28/01/2012, 11:33:20 PM
 *
 * Clase Java desarrollada por Edgar Ramos para 7i Software Factory el día 28/01/2012
 *
 * Para informacion sobre el uso de esta clase, asi como bugs, actualizaciones, o mejoras enviar un mail a
 * eramos@7i.com.mx
 *
 * Desarrollado por la célula de desarrollo de Zacatecas
 *
 */
package com.grupoquark.cic.business.tools;

import com.grupoquark.cic.model.contact.Contact;
import com.grupoquark.cic.model.period.Period;
import com.grupoquark.cic.model.person.Person;
import com.grupoquark.cic.model.register.MoneyRegister;
import com.grupoquark.cic.model.register.PointsRegister;
import com.grupoquark.cic.model.register.Register;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.util.Locale;
import java.util.ResourceBundle;
import org.apache.log4j.Logger;

/**
 * This Class provides locale specific toString methor for each one of the Model Classes.
 *
 * @author Edgar Ramos
 * @version 1.0
 * @author-mail eramos@7i.com.mx @date 28/01/2012
 */
public class Printer
{
    private static final Logger log = Logger.getLogger(Printer.class);
    private static final ResourceBundle labelsResourceBundle = ResourceBundle.getBundle("labels", Locale.getDefault());
    private static final ResourceBundle formatsResourceBundle = ResourceBundle.getBundle("formats", Locale.getDefault());
    private static final String MONEY_FORMAT_SOURCE = "moneyFmt";
    private static final String ADDRESS_LABEL_SOURCE = "addressStr";
    private static final String TELEPHONE_LABEL_SOURCE = "telephoneStr";
    private static final String OTHERS_LABEL_SOURCE = "othersStr";
    private static final String NAME_LABEL_SOURCE = "nameStr";
    private static final String DATE_LABEL_SOURCE = "dateStr";
    private static final String EARNED_LABEL_SOURCE = "earnedStr";
    private static final String LOST_LABEL_SOURCE = "lostStr";
    private static final String AMOUNT_LABEL_SOURCE = "amountStr";
    private static final String PERIOD_LABEL_SOURCE = "periodStr";
    private static String moneyFormat;
    private static String dateHead;
    private static String nameHead;
    private static String telephoneHead;
    private static String addressHead;
    private static String othersHead;
    private static String earnedHead;
    private static String lostHead;
    private static String amountHead;
    private static String periodHead;

    static
    {

        moneyFormat = formatsResourceBundle.getString(MONEY_FORMAT_SOURCE);
        nameHead = labelsResourceBundle.getString(NAME_LABEL_SOURCE);
        telephoneHead = labelsResourceBundle.getString(TELEPHONE_LABEL_SOURCE);
        addressHead = labelsResourceBundle.getString(ADDRESS_LABEL_SOURCE);
        othersHead = labelsResourceBundle.getString(OTHERS_LABEL_SOURCE);
        dateHead = labelsResourceBundle.getString(DATE_LABEL_SOURCE);
        earnedHead = labelsResourceBundle.getString(EARNED_LABEL_SOURCE);
        lostHead = labelsResourceBundle.getString(LOST_LABEL_SOURCE);
        amountHead = labelsResourceBundle.getString(AMOUNT_LABEL_SOURCE);
        periodHead = labelsResourceBundle.getString(PERIOD_LABEL_SOURCE);

        if (log.isTraceEnabled())
        {
            log.trace("Headlines readed");
        }
    }

    public static String toString(Person person)
    {
        StringBuilder returnValue = new StringBuilder();
        returnValue.append(nameHead).append(": ").append(person.getName());
        returnValue.append(" ").append(person.getFirstSurname());
        returnValue.append(" ").append(person.getSecondSurname());

        return returnValue.toString();
    }

    public static String toString(Contact contact)
    {
        StringBuilder returnValue = new StringBuilder();
        returnValue.append(telephoneHead).append(": ").append(contact.getTelephone()).append("\n");
        returnValue.append(addressHead).append(": ").append(contact.getAddress()).append("\n");
        returnValue.append(othersHead).append(": ").append(contact.getOthers());

        return returnValue.toString();
    }

    public static String toString(Register register)
    {
        StringBuilder returnedValue = new StringBuilder();
        DateFormat formattedDate = DateFormat.getDateInstance();

        returnedValue.append(dateHead).append(": ").append(formattedDate.format(register.getRegistrationDay()));

        return returnedValue.toString();
    }

    public static String toString(PointsRegister pointsRegister)
    {
        StringBuilder retunedValue = new StringBuilder();

        retunedValue.append(toString((Register) pointsRegister)).append(" ");
        retunedValue.append(earnedHead).append(": ").append(pointsRegister.getEarnedPoints()).append(" ");
        retunedValue.append(lostHead).append(": ").append(pointsRegister.getLostPoints());

        return retunedValue.toString();

    }

    public static String toString(MoneyRegister moneyRegister)
    {
        StringBuilder returnedValue = new StringBuilder();

        returnedValue.append(toString((Register) moneyRegister)).append(" ");
        returnedValue.append(amountHead).append(": $").append(new DecimalFormat(moneyFormat).format(moneyRegister.getAmount()));


        return returnedValue.toString();
    }

    public static String toString(Period period)
    {
        StringBuilder returnedValue = new StringBuilder();

        returnedValue.append(periodHead).append(": ").append(period.getSemester()).append(" ");
        returnedValue.append(period.getYear());

        return returnedValue.toString();
    }
}
